cmake_minimum_required(VERSION 3.1)  
project(MyQtProject)  
  
# 查找Qt5的组件  
find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)  
  
# 设置C++标准  
set(CMAKE_CXX_STANDARD 11)  
set(CMAKE_CXX_STANDARD_REQUIRED ON)  
  
# 添加头文件搜索路径，包括Qt的头文件  
include_directories(${CMAKE_SOURCE_DIR}/include ${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS})  
  
# 定义Qt5的MOC处理  
set(CMAKE_AUTOMOC ON)  
set(CMAKE_INCLUDE_CURRENT_DIR ON)  

find_package(OpenCV 3.2.0 REQUIRED)
# message([STATUS] "Opencv version " ${CMAKE_MODULE_PATH} " " ${CMAKE_ROOT} " " ${OpenCV_VERSION} "  " ${OpenCV_INCLUDE_DIRS} "  "${OpenCV_LIBS})
# directory of opencv headers
include_directories(${OpenCV_INCLUDE_DIRS})
  
# 添加可执行文件，并链接Qt库  
add_executable(my_qt_app main.cpp)  
target_link_libraries(my_qt_app 
                Qt5::Core 
                Qt5::Gui 
                Qt5::Widgets
                ${OpenCV_LIBS})  
  